#ifndef UTIL_H
#define UTIL_H

#include <iostream>
#include "math.h"

namespace ArrayUtils {

template <class Type>
void print(Type *data, unsigned int size) {
    for ( unsigned int i = 0; i < size; i++ )
        std::cout << data[i] << " ";
    std::cout << "\b";
}

template <class Type>
double mse(Type *data, unsigned int size) {
    Type acc = (Type) 0;
    for ( unsigned int i = 0; i < size; i++ )
        acc += pow(data[i], 2);
    return acc/size;
}

template <class Type>
double average(Type *data, unsigned int size) {
    Type acc = (Type) 0;
    for ( unsigned int i = 0; i < size; i++ )
        acc += data[i];
    return acc/size;
}
}

namespace MatrixUtils {
template <class Type>
Type* column(unsigned int column, Type **data, unsigned int rows) {
    Type * ret = new Type[rows];
    for ( unsigned int r = 0; r < rows; r++ )
        ret[r] = data[r][column];
    return ret;
}

template <class Type>
Type** create(unsigned int rows, unsigned int columns, Type defaultValue) {
    Type **data;
    data = new Type* [rows];
    for ( unsigned int r = 0; r < rows; r++ ) {
        data[r] = new Type[columns];
        for ( unsigned int c = 0; c < columns; c++ ) {
            data[r][c] = defaultValue;
        }
    }
    return data;
}

template <class Type>
void destroy(Type **data, unsigned int rows) {
    for ( unsigned int r = 0; r < rows; r++ )
        delete data[r];
    delete data;
}

}

#endif // UTIL_H
